<?php
/**************************************************************************
 * Naanal PHP Framework, Simple, Efficient and Developer Friendly
 * Ver 3.0, Copyright (C) <2010>  <Tamil Amuthan. R>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ************************************************************************/
class ClsNaanalmodconf
{
    private $database="";
    private $table="";
    private $arrAction=array();
    private $arrTableFieldMethod=array();
    private $arrTemplateVariable=array();
    private $arrTemplateFunction=array();
    public function __construct($database,$table) 
    {
        $this->database=$database;
        $this->table=$table;
    }
    public function addAction($name,$arrData=array())
    {
        $this->arrAction[$name]=$arrData;
    }
    public function addTableFieldGetter($name)
    {
        $this->arrTableFieldMethod[$name]["getter"]=true;
    }
    public function addTableFieldSetter($name)
    {
        $this->arrTableFieldMethod[$name]["setter"]=true;
    }
    public function addTemplateVariable($variable)
    {
        $this->arrTemplateVariable[$variable]="";
    }
    public function addFunctionCall($functionCall)
    {
        $this->arrTemplateFunction[$functionCall]="";
    }
    public function getActionNames()
    {
        return array_keys($this->arrAction);
    }
    public function getTableFieldMethods()
    {
        return $this->arrTableFieldMethod;
    }
    public function render()
    {
        $database="'".$this->database."'";
        if($this->database===false)
        {
            $database="false";
        }
        else if($this->database===true)
        {
            $database="true";
        }
        
        $table="'".$this->table."'";
        if($this->table===false)
        {
            $table="false";
        }
        else if($this->table===true)
        {
            $table="true";
        }
        
        $content='<?php
';
        
        $template_variables='$template_variables=array(';
        if($this->arrTemplateVariable)
        {
            $template_variables=$template_variables."'".implode("','",  array_keys($this->arrTemplateVariable))."'";
        }
        $template_variables=$template_variables.');
';
        $content=$content.$template_variables;
        
        $template_functions='$template_function_calls=array(';
        if($this->arrTemplateFunction)
        {
            $template_functions=$template_functions."'".implode("','",array_keys($this->arrTemplateFunction))."'";
        }
        $template_functions=$template_functions.');
';
        $content=$content.$template_functions;
        
        $actions='$actions=array(';
        if($this->arrAction)
        {
            foreach($this->arrAction as $action=>$actionData)
            {
                if(empty($actionData))
                {
                    $actionData="array()";
                }
                if($actions=='$actions=array(')
                {
                    $actions=$actions."'{$action}'=>{$actionData}";
                }
                else
                {
                    $actions=$actions.",
'{$action}'=>{$actionData}";
                }
            }
        }
        $actions=$actions.');
';
        $content=$content.$actions;

$content=$content."
\$list_has_header=false;
\$lang='default';
\$control_panel=false;
\$theme=true;
\$database={$database};
\$table={$table};
?>";
        return $content;
    }
}
?>